<!doctype html>
<html><head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> 
<meta name="keywords" content="carousel, jquery, responsive, fluid, elastic, resize, thumbnail, slider" />
<meta name="author" content="Codrops" />
<title>微评说客</title>
<link rel="stylesheet" type="text/css" href="/Public/home/style/public.css">
<link rel="stylesheet" type="text/css" href="/Public/home/style/style.css">
<link rel="stylesheet" type="text/css" href="/Public/home/style/font-awesome.css">
<script src="/Public/home/jquery/jquery-1.7.2.min.js"></script>
<script src="/Public/home/jquery/tab.js"></script>
<script type="text/javascript" src="/Public/Js/ueditor/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="/Public/Js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="/Public/Js/ueditor/ueditor.all.js"></script>
<style type="text/css">
.file {
    position: relative;
    display: inline-block;
    background: #D0EEFF;
    border: 1px solid #99D3F5;
    border-radius: 4px;
    padding: 4px 12px;
    overflow: hidden;
    color: #1E88C7;
    text-decoration: none;
    text-indent: 0;
    line-height: 20px;
}
.file input {
    position: absolute;
    font-size: 100px;
    right: 0;
    top: 0;
    opacity: 0;
}
.file:hover {
    background: #AADFFD;
    border-color: #78C3F3;
    color: #004974;
    text-decoration: none;
}
</style>
<script type="text/javascript">

var index={$count};
var qid={$qid};
var tid={$tid};
var status=0;
function adddata(){
	if(!$("#prifx_0").length>0 && qid==0){
		addquestionnaire();
		}
	else{
		var template='<p class="mk" id="prifx_{{index}}"><span>题目1</span><a href="postcontent.html?id='+qid+'" class="b1">编辑</a><a href="javascript:remove({{index}},0)" class="b2">删除</a></p>';
		$("#mk2").append(template.replace(/{{index}}/g,index++));
		
	}
}

$(document).ready(function(e) {
    lo();
});

function lo(){
	$("#bus4").click(function(){
		 var ue=UE.getEditor('tex');
		 ue.getContent();
		 var str=ue.queryCommandValue( 'fontsize' );
		 str=str.substring(0,str.length-2);
		 var num =parseInt(str)+1+"px";
		 ue.execCommand( 'fontsize', num );
	});
	$("#bus3").click(function(){
		 var ue=UE.getEditor('tex');
		 ue.getContent();
		 var str=ue.queryCommandValue( 'fontsize' );
		 str=str.substring(0,str.length-2);
		 var num =parseInt(str)-1+"px";
		 ue.execCommand( 'fontsize', num );
		 
	});
	$("#bus2").click(function(){
		
		    $(".edui-for-insertvideo .edui-button-body")[0].click();
		 
	});
	$("#bus1").click(function(){
		
	    $(".edui-for-insertimage .edui-button-body")[0].click();
	 
});
	$("#button").click(function(){
		
		adddata();
		
	});
}
function remove(id,cid){
	
	if(cid!=0){
		delquestion(id,cid);
	}
	else{
		index--;
		$("#prifx_"+id).remove();
	}
}	

function delquestion(pid,id){
	 $.post("/home/index/delquestion",
			  {
		 		id:id
			  },
			  function(data){
				
				 var status=data.status;
				  if(status==1){
					  	index--;
						$("#prifx_"+pid).remove();
						}
						else{
							alert("系统忙，请稍后！");
						}
			  });
	
}

function publicdata(){
	if(!$('#current').is(":visible")){
		var isfilled=checkfilled(2);
		if(isfilled){
			publicquestion();
		}
		else{
			alert("请填写完整信息！");
		}
	
	}
	else{
		var isfilled=checkfilled(1);
		if(isfilled){
			$("#topic").submit();
		}
		else{
			alert("请填写完整信息！");
		}
	}
}

function checkfilled(type){
	
	var isfilled=true;
	if(type==2){
	if($('#qname').val()=="")isfilled=false;
	if($('#qdes').val()=="")isfilled=false;
	if(index==0)isfilled=false;
	}
	else{
		
		if($('#title').val()=="")isfilled=false;
		if(!UE.getEditor('tex').hasContents())isfilled=false;
		if($('#pic').val()=="" && tid==0)isfilled=false;
	}
	return isfilled;
	
}

</script>
<style>
	html,body{ background:#f2f2f2;}
</style>
</head>

<body>
<header class="index-header">
	<h1>发布</h1>
    <a href="javascript:window.history.back()" class="icon-circle-arrow-left kl"></a>
    <input type="button" value="发布" class="header-button" onclick="publicdata()">
</header>

<section class="table">
	<div class="table-title tab_title">
    	<ul>
    		<li <eq name="cid" value="0">class="current"</eq>>新帖发布</li>
    		<li <neq name="cid" value="0">class="current"</neq>>问卷发布</li>
            <div class="clears"></div>
    	</ul>
    </div>
    <div class="table-nr tab_nr">
    	<div id="current" class="table-block nk tab_block" <neq name="cid" value="0">style="display:none" </neq>>
    	<form id='topic' enctype='multipart/form-data'  method='post' action="/home/index/addtopic">
    	 <input type="hidden" name="id" value="{$tid}">
        	<p><select name="class" id=""> 
        	<volist name="class" id="vo">
                <option value="{$vo.id}">{$vo.name}</option>
                </volist>
                </select><span class="icon-caret-down"></span></p>
            <p><input id="title" name="title" type="text" placeholder="文章标题" value="{$tinfo.title}"></p>
            
             <a href="javascript:;" class="file">上传话题封面
  			  <input id="pic" type="file" name="pic" class="form-control"  />
			</a>
            <div style="margin-bottom:0px;">
          
            <script id="tex" name="content" type="text/plain" style="width:100%;height:300px;">{$tinfo['context']|htmlspecialchars_decode}
			</script>
            </div>
           
            </form>
        </div>
         
    	<div class="table-block tab_block" <eq name="cid" value="0">style="display:none" </eq>>
    	
        	<p><input id="qname" type="text" placeholder="请输入问卷名称" value="{$questionnaire.name}"></p>
        	<div class="mk2" id="mk2">
        	<p class="mk2"> <textarea id="qdes" placeholder="请输入问卷说明" value="">{$questionnaire.description}</textarea></p>
        	<volist name="info" id="vo">
        	<p class="mk" id="prifx_{$i-1}"><span>{$vo.name}</span><a href="postcontent.html?id={$id}&cid={$vo.id}" class="b1">编辑</a><a href="javascript:remove({$i-1},{$vo.id})" class="b2">删除</a></p>
        	</volist>
        	</div>
        	<p><input type="button" value="+添加新题" class="nuy" id="button"></p>
        	
        </div>
        
    </div>
</section>
<div class="hh"></div>
<nav>
	<ul>
		<li>
        	<a href="/home/index/index.html" class="n1">
				<p></p>
				<span>首页</span>
			</a>
        </li>
		<li>
        	<a href="/home/index/questionnaire.html" class="n2">
				<p></p>
				<span>问卷</span>
			</a>
        </li>
		<li>
        	<a href="/home/index/post.html" class="n3">
				<p class="current"></p>
				<span>发布</span>
			</a>
        </li>
		<li>
        	<a href="/home/index/mine.html" class="n4">
				<p></p>
				<span>我的</span>
			</a>
        </li>
	</ul>
</nav>
</body>
<script type="text/javascript">
function addquestionnaire(){
	 $.post("/home/index/addquestionnaire",
			  {
		 		name:$('#qname').val(),
	 			description:$('#qdes').val()
			  },
			  function(data){
				  qid=data.id;
				  status=data.status;
				  if(status==1){
						var template='<p class="mk" id="prifx_{{index}}"><span>题目1</span><a href="postcontent.html?id='+qid+'" class="b1">编辑</a><a href="javascript:remove({{index}})" class="b2">删除</a></p>';
						$("#mk2").append(template.replace(/{{index}}/g,index++));
						}
						else{
							alert("系统忙，请稍后！");
						}
			  });
	
}

function publicquestion(){
	 $.post("/home/index/publicquestion",
			  {
		 		id:qid,
		 		name:$('#qname').val(),
		 		description:$('#qdes').val()
			  },
			  function(data){
				alert(data.msg);
			  });
	
}


</script>
<script type="text/javascript">

    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
     UE.getEditor('tex', {
    	 toolbars: [
                    ['insertvideo','insertimage']
                ],
               autoHeightEnabled: false
    
    }
    );


    function isFocus(e){
        alert(UE.getEditor('editor').isFocus());
        UE.dom.domUtils.preventDefault(e)
    }
    function setblur(e){
        UE.getEditor('editor').blur();
        UE.dom.domUtils.preventDefault(e)
    }
    function insertHtml() {
        var value = prompt('插入html代码', '');
        UE.getEditor('editor').execCommand('insertHtml', value)
    }
    function createEditor() {
        enableBtn();
        UE.getEditor('editor');
    }
    function getAllHtml() {
        alert(UE.getEditor('editor').getAllHtml())
    }
    function getContent() {
        var arr = [];
        arr.push("使用editor.getContent()方法可以获得编辑器的内容");
        arr.push("内容为：");
        arr.push(UE.getEditor('editor').getContent());
        alert(arr.join("\n"));
    }
    function getPlainTxt() {
        var arr = [];
        arr.push("使用editor.getPlainTxt()方法可以获得编辑器的带格式的纯文本内容");
        arr.push("内容为：");
        arr.push(UE.getEditor('editor').getPlainTxt());
        alert(arr.join('\n'))
    }
    function setContent(isAppendTo) {
        var arr = [];
        arr.push("使用editor.setContent('欢迎使用ueditor')方法可以设置编辑器的内容");
        UE.getEditor('editor').setContent('欢迎使用ueditor', isAppendTo);
        alert(arr.join("\n"));
    }
    function setDisabled() {
        UE.getEditor('editor').setDisabled('fullscreen');
        disableBtn("enable");
    }

    function setEnabled() {
        UE.getEditor('editor').setEnabled();
        enableBtn();
    }

    function getText() {
        //当你点击按钮时编辑区域已经失去了焦点，如果直接用getText将不会得到内容，所以要在选回来，然后取得内容
        var range = UE.getEditor('editor').selection.getRange();
        range.select();
        var txt = UE.getEditor('editor').selection.getText();
        alert(txt)
    }

    function getContentTxt() {
        var arr = [];
        arr.push("使用editor.getContentTxt()方法可以获得编辑器的纯文本内容");
        arr.push("编辑器的纯文本内容为：");
        arr.push(UE.getEditor('editor').getContentTxt());
        alert(arr.join("\n"));
    }
    function hasContent() {
        var arr = [];
        arr.push("使用editor.hasContents()方法判断编辑器里是否有内容");
        arr.push("判断结果为：");
        arr.push(UE.getEditor('editor').hasContents());
        alert(arr.join("\n"));
    }
    function setFocus() {
        UE.getEditor('editor').focus();
    }
    function deleteEditor() {
        disableBtn();
        UE.getEditor('editor').destroy();
    }
    function disableBtn(str) {
        var div = document.getElementById('btns');
        var btns = domUtils.getElementsByTagName(div, "button");
        for (var i = 0, btn; btn = btns[i++];) {
            if (btn.id == str) {
                domUtils.removeAttributes(btn, ["disabled"]);
            } else {
                btn.setAttribute("disabled", "true");
            }
        }
    }
    function enableBtn() {
        var div = document.getElementById('btns');
        var btns = domUtils.getElementsByTagName(div, "button");
        for (var i = 0, btn; btn = btns[i++];) {
            domUtils.removeAttributes(btn, ["disabled"]);
        }
    }

    function getLocalData () {
        alert(UE.getEditor('editor').execCommand( "getlocaldata" ));
    }

    function clearLocalData () {
        UE.getEditor('editor').execCommand( "clearlocaldata" );
        alert("已清空草稿箱")
    }

</script>

</html>
